package cn.liuhulu.entity;

import java.util.Optional;

import cn.liuhulu.tool.Tools;
import javafx.beans.property.SimpleStringProperty;

/**
 * 账单
 * 
 * @author liula
 *
 */
public class ProductBill {

	private SimpleStringProperty name; // 名称
	private SimpleStringProperty spec; // 规格
	private SimpleStringProperty quantity; // 数量
	private SimpleStringProperty price; // 价格
	private SimpleStringProperty itemPrice; // 条目总格

	public ProductBill(String name, String spec, String price, String quantity) {
		super();
		this.name = new SimpleStringProperty(name);
		this.spec = new SimpleStringProperty(spec);
		this.price = new SimpleStringProperty(price);
		this.quantity = new SimpleStringProperty(quantity);
		setItemPrice();

	}

	public ProductBill(Product product, String quantity) {
		super();
		this.name = new SimpleStringProperty(product.getName());
		this.spec = new SimpleStringProperty(product.getSpec());
		this.price = new SimpleStringProperty(product.getPrice());
		this.quantity = new SimpleStringProperty(quantity);
		setItemPrice();
	}

	public String getName() {
		return name.get();
	}

	public ProductBill setName(String name) {
		this.name = new SimpleStringProperty(name);
		return this;
	}

	public String getSpec() {
		return spec.get();
	}

	public ProductBill setSpec(String spec) {
		this.spec = new SimpleStringProperty(spec);
		return this;
	}

	public String getPrice() {
		return price.get();
	}

	public ProductBill setPrice(String price) {
		this.price = new SimpleStringProperty(price);
		return this;
	}

	public String getQuantity() {
		return quantity.get();
	}

	public ProductBill setQuantity(String quantity) {
		this.quantity = new SimpleStringProperty(quantity);
		return this;
	}

	public String getItemPrice() {
		return itemPrice.get();
	}

	public double getItemPriceDouble() {
		return Double.valueOf(itemPrice.get());
	}

	public ProductBill setItemPrice(String itemPrice) {
		this.itemPrice = new SimpleStringProperty(itemPrice);
		return this;
	}

	public ProductBill setItemPrice() {
		Optional<String> multiply = Tools.multiply(getPrice(), getQuantity());
		this.itemPrice = new SimpleStringProperty(multiply.isPresent() ? multiply.get() : "价格或数量错误");
		return this;
	}

}
